package com.wdc.binarytree;

/**
 * 二叉搜索树的插入操作 力扣701
 */
@SuppressWarnings("all")
public class Eo4Leetcode701 {
     class TreeNode {
         int val;
         TreeNode left;
         TreeNode right;
         TreeNode() {}
         TreeNode(int val) { this.val = val; }
         TreeNode(int val, TreeNode left, TreeNode right) {
             this.val = val;
             this.left = left;
             this.right = right;
         }
     }

    public TreeNode insertIntoBST(TreeNode root, int val) {

         if (root == null){
             return new TreeNode(val);
         }
        //如果大于就放在节点的右边，小于就放在节点的左边
        if(root.val < val) {
            root.left = insertIntoBST(root.right,val);
        } else if (root.val > val ) {
            root.right = insertIntoBST(root.left,val);
        }

        return root;
    }



}
